package com.atguigu.juc.t3;

public class test {
    public static void main(String[] args) {
        Mirror mirror = new Mirror();
        Lip lip = new Lip();

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "我是小红");
            synchronized (mirror) {
                System.out.println(Thread.currentThread().getName() + "我第一步拿到镜子了");
                synchronized (lip) {
                    System.out.println(Thread.currentThread().getName() + "我第二步拿到口红了，可以开始化妆了");
                    try {
                        Thread.sleep(2000);
                        System.out.println(Thread.currentThread().getName() + "化妆结束，释放资源");
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }, "小红").start();

        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "我是小兰");
            synchronized (lip) {
                System.out.println(Thread.currentThread().getName() + "我第一步拿到口红了");
                synchronized (mirror) {
                    System.out.println(Thread.currentThread().getName() + "我第二步拿到镜子了，可以开始化妆了");
                    try {
                        Thread.sleep(2000);
                        System.out.println(Thread.currentThread().getName() + "化妆结束，释放资源");
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }, "小兰").start();
    }
}
